<?php

namespace Home\Controller;

use Think\Controller;

class LoginController extends CommonController {
    public function verify() {
        $config =    array(
    
            'fontSize'    =>    16,    // 驗證碼字體大小
    
            'length'      =>    5,     // 驗證碼位數
    
            'useCurve'    =>    false, // 關閉驗證碼雜點
    
            'useCurve' => false,
    
        );
    
         
    
        $Verify = new \Think\Verify($config);
    
        $Verify->codeSet = '0123456789';
    
        $Verify->entry();
    /* $data['status'] = 1;
    $data['code'] =  $Verify->entry(); */
    }
	//验证登录
    public function logincl() {
    	//if (IS_POST) {
	    	$username=trim(I('post.account'));
			$pwd=trim(I('post.password'));
				//$where['UE_phone'] = $username;
				$where['UE_verMail'] = $username;
				//$where['_logic'] = 'or';
				$user=M('user')->where($where)->find();
				if(!$user || $user['ue_password']!=md5($pwd)){ 
					$this->ajaxReturn( array('msg'=>'账号或密码错误!','status'=>-1) );
				}elseif($user['ue_status']=='1'){
					$this->ajaxReturn( array('msg'=>'账号被禁用!','status'=>-2) );
				}else{
					//$this->cspaycl($user);
					$record1['date']= date ( 'Y-m-d H:i:s', time () );
					$record1['ip'] = I('post.ip');
					$record1['user'] = $user[ue_account];
					$record1['leixin'] = 0;
					M ( 'drrz' )->add ( $record1 );
					//获取token
					$where_token['uid'] = $user['ue_id'];
					$token_log = M('Token')->where($where_token)->find();
					$token = $token_log['token'];
					if(!$token_log){
					    $data_token['uid']   = $user['ue_id'];
					    $data_token['token'] = $user['ue_id'].md5(time());
					    M('Token')->add($data_token);
					    $token = $data_token['token'];
					}
					$data_return['token'] = $token;
					$data_return['msg'] = '登录成功!';
					$data_return['status'] = 1;
					$this->ajaxReturn($data_return);
				}
    	//}
    }
    public function cspaycl ($data)
    {
        if ( !is_array($data) )
        {
    		$data_return['msg'] = '参数错误!';
    		$data_return['status'] = 1;
    		$this->ajaxReturn($data_return);
        }
         
         
        $uname=$data['ue_account'];
        $fname=$data['ue_accname'];
        $uid=$data['ue_id'];
         
        $ppdd= M('ppdd');
        $where=array();
        iniverify();
        $where['p_user'] = $uname;
        $where['zt'] =0;
        $rs=$ppdd->where($where)->select();
        if($data['ue_status'] == 2){
            return ;
        }
        if ( $rs )
        {
             
            $jjdktime=C("jjdktime");
            $jjhydjmsg=C("jjhydjmsg");
            $jjhydjkcsjmoeney=C("jjhydjkcsjmoeney");
            $nowtime=time();
            $cszt=0;
            foreach( $rs as $v  )
            {
    
                $pdtime = strtotime($v['date']);
                $cstime=$pdtime+3600 *$jjdktime;
                 
                if ( $cstime<$nowtime )
                {
                    $cszt=1;
                    break;
                     
                }
            }
             
            if ( $cszt )
            {
                $user= M('user');
                $data2=array();
                $data2['UE_ID']=$uid;
                $data2['UE_status']=1;
                $user->save($data2);
    
                if ( $jjhydjkcsjmoeney && $fname )
                {
                    $where=array();
                    $where['UE_account'] = $fname;
                    $user->where($where)->setDec('UE_money',$jjhydjkcsjmoeney);
    
                }
                $data_return['msg'] = $jjhydjmsg;
                $data_return['status'] = -1;
                $this->ajaxReturn($data_return);
            }
             
        }
    }
}